package com.inheritance.controller;

import com.inheritance.common.Result;
import com.inheritance.entity.Tabs;
import com.inheritance.service.TabsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.util.List;


@RestController
@RequestMapping("/tabs")
public class TabsController {
    @Resource
    private TabsService tabsService;

    // 获取tab列表
    @GetMapping("/list")
    public Result<?> list() {
        return Result.success("查询成功", tabsService.list());
    }

    // 新增tab
    @PostMapping("upload")
    public Result<?> upload(@RequestBody Tabs tabs) {
        int i = tabsService.upload(tabs);
        if (i == 1) {
            return Result.success("新增成功");
        } else {
            return Result.error("新增失败");
        }
    }

    // 删除tab
    @DeleteMapping("/delete/{id}")
    public Result<?> delete(@PathVariable String id) {
        int i = tabsService.delete(id);
        if (i > 0) {
            return Result.success("删除成功");
        } else {
            return Result.error("删除失败");
        }
    }

    // 修改tab
    @PutMapping("/update")
    public Result<?> update(@RequestBody Tabs tabs) {
        int i = tabsService.update(tabs);
        if (i > 0) {
            return Result.success("修改成功");
        } else {
            return Result.error("修改失败");
        }
    }

}
